//
//  SerialQueueDemo.m
//  MultiperThreadTest02
//
//  Created by FelixYin on 2020/4/5.
//  Copyright © 2020 FelixYin. All rights reserved.
//

#import "SerialQueueDemo.h"

/*
 
 利用串行队列解决多线程 访问数据问题，串行队列是按照任务时间先后顺序执行的
 
 */
@interface SerialQueueDemo ()

@property (nonatomic,strong) dispatch_queue_t moneyQueue;
@property (nonatomic,strong) dispatch_queue_t ticketQueue;

@end

@implementation SerialQueueDemo

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.moneyQueue = dispatch_queue_create("MoneyQueue", DISPATCH_QUEUE_SERIAL);
        self.ticketQueue = dispatch_queue_create("MoneyQueue", DISPATCH_QUEUE_SERIAL);
    }
    return self;
}

- (void)saveMoney{
    dispatch_sync(self.moneyQueue, ^{
        [super saveMoney];
    });
}

- (void)drawMoney{
    dispatch_sync(self.moneyQueue, ^{
        [super drawMoney];
    });
}

- (void)saleTicket{
    dispatch_sync(self.ticketQueue, ^{
        [super saleTicket];
    });
}

@end
